fix(idl): avoid quoted string constant values#4580
Conversation
|
I'm not sure if this is workable, at least in v1, as this would be a breaking change to IDL consumers. For example, anchor/lang/attribute/program/src/declare_program/mods/constants.rs Lines 25 to 37 in 4172f22 So this causes declare program to emit |
23fa1c3 to
033514d
Compare
i updated the approach so the JSON IDL still keeps string constant values as Rust expressions, preserving compatibility with declare_program and other IDL consumers.... the change is now limited to the generated TypeScript type helper, where string literal constants are normalized for target/types/*.ts only... |
|
What exactly are the new changes doing? |
033514d to
d0bcada
Compare
the new changes keep the actual JSON IDL unchanged for compatibility: string constants are still stored as Rust expressions, e.g. the only behavior change is in the generated TypeScript type helper ( |
|
Can you add a test for the real behavioral change, and update the PR title/description to reflect it? |
|
Actually sorry, I'm going to close this based on the reasoning in the linked issue. I don't think this break is worth it. |
Fixes #3607
Summary
#[constant]values using their actual string contents instead of Rust debug formatting"\"favor\""&strconstant in the IDL fixtureTesting
cargo test -p anchor-syncargo test -p anchor-cli idl_ts_preserves_literal_valuesCARGO_NET_OFFLINE=true target/debug/anchor idl build -o /private/tmp/idl-3607.jsondiff -u tests/idl/idls/idl.json /private/tmp/idl-3607.jsontarget/debug/anchor idl type /private/tmp/idl-3607.json > /private/tmp/idl-3607.tsrg -n 'seedPrefix|favor|\\"favor\\"' /private/tmp/idl-3607.tsgit diff --check